home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / ratpac.doc < prev    next >
Text File  |  1995-03-31  |  2KB  |  48 lines

  1. (User.programs) 
  2. Item: 211 by _tasmith at hpcvbbs.UUCP 
  3. Author: [Ted A Smith] 
  4.   Subj: Rational number package 
  5.   Date: Wed Feb 06 1991 20:21  
  6.  
  7. [Note: On this disk, RATPAC is a directory object, and RATPAC.LIB is a library 
  8. object.  They have the same functionality.  -jkh-] 
  9.  
  10. Here is a rational math package: 
  11.  
  12.   QAdd  Add two numbers 
  13.   QSub  Subtract 
  14.   QMul  Multiply 
  15.   QDiv  Divide 
  16.   QNeg  Negate 
  17.   QInv  Reciprocate 
  18.   Q->I  Convert a number to an integer 
  19.   Q->F  Convert a number to a continued fraction 
  20.   QF->  Convert a continued fraction to a number 
  21.   ->NUM Convert a number to a real 
  22.  
  23. CST will be a menu. 
  24.  
  25. Input numbers may be real or rationals. 
  26. Rationals are represented as 'i+n/d' or 'n/d', e.g. 
  27.   5 2 QDiv        ==>  '5/2' 
  28.   '5/2' 2 QAdd    ==>  '4+1/2' 
  29.  
  30. I took reasonable care to preserve high accuracy. 
  31. I don't have a clue what possesed me to write this. 
  32. There isn't near enough error checking on input expressions. 
  33.  
  34. P.S. By truncating a continued fraction you can get the 'best' 
  35. approximation to your input number with a denominator <= the 
  36. resultant denominator.  E.g. 
  37.   'Pi' ->NUM                   ==>  3.14159265359 
  38.   3.14159265359 Q->F           ==>  { 3 7 15 1 292 1 1 3 } 
  39.   { 3 7 15 1 292 1 1 3 } QF->  ==>  3.14159265359 
  40.   { 3 7 15 1 } QF->            ==>  '355/113' 
  41.   { 3 7 } QF->                 ==>  '22/7' 
  42.  
  43. [Note: By decrementing (not dropping) the last number in the list, you reduce 
  44.  the resulting fraction by the smallest possible amount.  This fact is what 
  45.  makes the DEC2FRAC program work.  Number theory buffs will enjoy taking 
  46.  successive results from DEC2FRAC and feeding them to Ted's Q->F function. 
  47.  -jkh-] 
  48.